var app = getApp(), tcity = require("../../resource/js/userinfoUtil.js");

tcity = require("../../../utils/citys.js");

Page({
    data: {
        is_show_share: !1,
        tabIndex: 0,
        isEmpty: !1,
        hasMore: !0,
        page: 1,
        data: [],
        pageIndex: 1,
        hasSlide: !1,
        indicatorDots: !1,
        autoplay: !0,
        interval: 5e3,
        duration: 1e3,
        circular: !0,
        psize: 5,
        paihang: 1,
        is_load_more: !0,
        issearch: !1,
        inputVal: "",
        ismore: !0,
        bannser_show: !1,
        winWidth: 0,
        winHeight: 0,
        currentTab: 0,
        provinces: [],
        province: "",
        citys: [],
        city: "",
        countys: [],
        county: "",
        value: [ 0, 0, 0 ],
        values: [ 0, 0, 0 ],
        idx: 0,
        imgUrls: "",
        cityclass: "",
        condition: !1,
        conditionb: !1,
        _is_load: !0,
        ejecttp: !1,
        _pl_vity: !1,
        showModalStatus: !1
    },
    bindChange: function(t) {
        var a = t.detail.value, e = this.data.values, n = this.data.cityData;
        if (a[0] == e[0]) if (a[1] == e[1]) a[2] == e[2] || this.setData({
            county: this.data.countys[a[2]],
            values: a
        }); else {
            for (var i = [], s = 0; s < n[a[0]].sub[a[1]].sub.length; s++) i.push(n[a[0]].sub[a[1]].sub[s].name);
            this.setData({
                city: this.data.citys[a[1]],
                countys: i,
                values: a,
                value: [ a[0], a[1], 0 ]
            });
        } else {
            for (var r = [], d = [], o = 0; o < n[a[0]].sub.length; o++) r.push(n[a[0]].sub[o].name);
            for (var c = 0; c < n[a[0]].sub[0].sub.length; c++) d.push(n[a[0]].sub[0].sub[c].name);
            this.setData({
                province: this.data.provinces[a[0]],
                city: n[a[0]].sub[0].name,
                citys: r,
                county: n[a[0]].sub[0].sub[0].name,
                countys: d,
                values: a,
                value: [ a[0], 0, 0 ]
            });
        }
    },
    onLoad: function(t) {
        var a = this;
        app.util.footer(this), app.util.getUserInfo(function(t) {
            a.setData({
                userInfo: t
            });
        }), setTimeout(function() {
            a.load_list(0, page_0), a.load_list_init();
        }, 650), tcity.init(a);
        for (var e = a.data.cityData, n = [], i = [], s = [], r = 0; r < e.length; r++) n.push(e[r].name);
        for (var d = 0; d < e[0].sub.length; d++) i.push(e[0].sub[d].name);
        for (var o = 0; o < e[0].sub[0].sub.length; o++) s.push(e[0].sub[0].sub[o].name);
        a.setData({
            provinces: n,
            citys: i,
            countys: s,
            province: e[0].name,
            city: e[0].sub[0].name,
            county: e[0].sub[0].sub[0].name
        }), app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card"
            },
            success: function(t) {
                0 == t.data.errno && a.setData({
                    my_card_info: t.data.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetCityBanner",
            data: {
                m: "bbyscm_card"
            },
            success: function(t) {
                0 == t.data.errno && a.setData({
                    imgUrls: t.data.data,
                    hasSlide: !0
                });
            },
            fail: function() {},
            complete: function() {}
        }), app.util.request({
            url: "entry/wxapp/Setup",
            data: {
                m: "bbyscm_card"
            },
            success: function(t) {
                a.setData({
                    setup: t.data.data,
                    apikey: t.data.data.apikey
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetCityclass",
            data: {
                m: "bbyscm_card"
            },
            success: function(t) {
                a.setData({
                    menu_list: t.data.data,
                    menu_type: t.data.message
                }), a.setData({
                    currentTabmenu: 1
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetGun",
            data: {
                m: "bbyscm_card"
            },
            success: function(t) {
                a.setData({
                    guns: t.data.data
                });
            }
        });
    },
    onShow: function() {
        this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.onPullDownRef(!0), this.setData({
            sysinfo: app.globalData.sysinfo
        });
    },
    swichNav: function(t) {
        var a = this;
        if (a.data.currentTab === t.currentTarget.dataset.current) return !1;
        a.setData({
            currentTab: t.currentTarget.dataset.current
        }), this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.onPullDownRef(1), 0 == a.data.currentTab ? (this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.onPullDownRef(1)) : 1 == a.data.currentTab ? "" == wx.getStorageSync("latitude") && "" == wx.getStorageSync("longitude") ? wx.getLocation({
            complete: function(t) {
                wx.setStorageSync("latitude", t.latitude), wx.setStorageSync("longitude", t.longitude), 
                this.setData({
                    is_load_more: !0,
                    pageIndex: 1,
                    data: []
                }), this.onPullDownRef(1);
            }
        }) : (this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.onPullDownRef(1)) : 2 == a.data.currentTab && (this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.onPullDownRef(1));
    },
    onPullDownRef: function(t) {
        var n = this, a = n.data.data;
        t = t || !1;
        var e = {};
        e.type = [ "popularity", "collect" ][this.data.tabIndex], e.pageIndex = n.data.pageIndex, 
        e.s_key = n.data.s_key, e.currentTab = n.data.currentTab, e.lon = wx.getStorageSync("longitude"), 
        e.lat = wx.getStorageSync("latitude"), e.psize = n.data.psize, e.province = n.data.province, 
        e.city = n.data.city, e.county = n.data.county, e.cityclass = n.data.cityclass, 
        e.m = "bbyscm_card", app.util.request({
            url: "entry/wxapp/GetCityx",
            data: e,
            success: function(t) {
                0 == t.data.errno && (a = a.concat(t.data.data.list), n.setData({
                    data: a,
                    gtotal: t.data.data.gtotal,
                    _is_load: !1
                }));
            }
        }), 1 == n.data.currentTab ? wx.getLocation({
            type: "wgs84",
            success: function(t) {
                var a = t.latitude, e = t.longitude;
                t.speed, t.accuracy;
                new (require("../../../utils/qqmap-wx-jssdk.js"))({
                    key: n.data.apikey
                }).reverseGeocoder({
                    location: {
                        latitude: a,
                        longitude: e
                    },
                    success: function(t) {
                        n.setData({
                            district: t.result.address_component.district
                        }), wx.setNavigationBarTitle({
                            title: t.result.address_component.district + "同城信息"
                        });
                    },
                    fail: function(t) {},
                    complete: function(t) {}
                });
            }
        }) : wx.setNavigationBarTitle({
            title: "信息库"
        });
    },
    onHide: function() {},
    onReachBottom: function() {
        this.data.pageIndex < this.data.gtotal && (this.setData({
            pageIndex: this.data.pageIndex + 1
        }), this.onPullDownRef(!0));
    },
    onUnload: function() {},
    eject: function(t) {
        this.setData({
            ejecttp: !this.data.ejecttp,
            tpid: t.currentTarget.id
        });
    },
    ejectc: function(t) {
        this.setData({
            showModalStatus: !1,
            ejecttp: !1
        });
    },
    show_comments: function(t) {
        console.log("弹出评论", t);
        this.setData({
            reply_id: t.currentTarget.dataset.reply_id,
            p_card: t.currentTarget.dataset.p_card,
            p_name: t.currentTarget.dataset.p_name,
            pl_id: t.currentTarget.id,
            pl_openid: t.currentTarget.dataset.pl_openid,
            pl_name: t.currentTarget.dataset.pl_name,
            pl_card: t.currentTarget.dataset.pl_card,
            idx: t.currentTarget.dataset.idx,
            ejecttp: !1,
            showModalStatus: !0
        });
    },
    formSubmit_send_comments: function(t) {
        var a = t.detail.formId, n = this, e = t.detail.value.reply_id, i = t.detail.value.p_card, s = t.detail.value.p_name, r = t.currentTarget.id, d = t.detail.value.pl_openid, o = t.detail.value.pl_card, c = t.detail.value.pl_name, u = t.detail.value.pl_content, l = t.detail.value.idx;
        "" == i ? wx.showToast({
            title: "用户授权信息无,不可发布评论!"
        }) : "" == u ? wx.showToast({
            title: "评论内容不能为空!"
        }) : app.util.request({
            url: "entry/wxapp/Psend_comments",
            data: {
                m: "bbyscm_card",
                form_id: a,
                reply_id: e,
                pl_id: r,
                p_card: i,
                p_name: s,
                pl_card: o,
                pl_name: c,
                pl_openid: d,
                pl_content: u
            },
            success: function(t) {
                n.setData({
                    showModalStatus: !1
                });
                var a = l, e = n.data.data;
                e[a].pl_vity = t.data.data, n.setData({
                    data: e
                });
            }
        });
    },
    delete_comments: function(t) {
        var n = this, a = t.currentTarget.dataset.delid, e = t.currentTarget.id, i = t.currentTarget.dataset.idx;
        wx.showModal({
            title: "提示",
            content: "您确定删除此条评论吗？",
            confirmText: "确定删除",
            success: function(t) {
                t.confirm && ("" == a ? wx.showToast({
                    title: "用户授权信息无,不可删除评论!"
                }) : app.util.request({
                    url: "entry/wxapp/Psend_comments",
                    data: {
                        m: "bbyscm_card",
                        pl_id: e,
                        del_id: a
                    },
                    success: function(t) {
                        var a = i, e = n.data.data;
                        e[a].pl_vity = t.data.data, n.setData({
                            data: e
                        });
                    }
                }));
            }
        });
    },
    pl_vity_open: function(t) {
        var a = t.currentTarget.dataset.idx, e = t.currentTarget.dataset.vity_open, n = this.data.data;
        n[a].vity_open = !e, this.setData({
            data: n
        });
    },
    ptl_vity_open: function(t) {
        var a = t.currentTarget.dataset.idx, e = t.currentTarget.dataset.ptidx, n = t.currentTarget.dataset.ptvity_open, i = this.data.data;
        i[a].pl_vity[e].ptvity_open = !n, this.setData({
            data: i
        });
    },
    f_vity_open: function(t) {
        var a = t.currentTarget.dataset.idx, e = t.currentTarget.dataset.fvity_open, n = this.data.data;
        n[a].fvity_open = !e, this.setData({
            data: n
        });
    },
    fabulous: function(t) {
        var n = this, a = n.data.my_card_info.id, e = n.data.my_card_info.cardname, i = t.currentTarget.id, s = t.currentTarget.dataset.idx, r = t.currentTarget.dataset.xx;
        "" == a ? wx.showToast({
            title: "用户授权信息无,无权限点赞!"
        }) : app.util.request({
            url: "entry/wxapp/Psend_fabulous",
            data: {
                m: "bbyscm_card",
                xx: r,
                pl_id: i,
                p_card: a,
                p_name: e
            },
            success: function(t) {
                n.setData({
                    ejecttp: !1
                });
                var a = s, e = n.data.data;
                e[a].fabulous = t.data.data, e[a].pt_openid = t.data.message, n.setData({
                    data: e
                });
            }
        });
    },
    open: function(t) {
        var a = parseInt(t.currentTarget.dataset.tabIndex);
        this.setData({
            tabIndex: a
        }), this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.setData({
            condition: !this.data.condition
        }), this.onPullDownRef(1);
    },
    open_mlist: function(t) {
        var a = parseInt(t.currentTarget.dataset.tabIndex);
        this.setData({
            tabIndex: a
        }), this.setData({
            is_load_more: !0,
            pageIndex: 1,
            data: []
        }), this.setData({
            conditionb: !this.data.conditionb
        }), this.setData({
            cityclass: t.currentTarget.id
        }), this.onPullDownRef(1);
    },
    onNavigateTap2: function(t) {
        JSON.stringify(t.detail.value);
        var a = t.detail.formId, e = t.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostFormid",
            data: {
                m: "bbyscm_card",
                form_id: a
            }
        }), wx.navigateTo({
            url: "../info/info?card_id=" + e
        });
    },
    look_card_info_bind: function(t) {
        wx.navigateTo({
            url: "../../card/info/info?card_id=" + t.currentTarget.dataset.cardid
        });
    },
    onNavigateTap: function(t) {
        var a = t.currentTarget.dataset.url, e = t.currentTarget.dataset.wx_appid, n = t.currentTarget.dataset.wx_path;
        e ? wx.navigateToMiniProgram({
            appId: e,
            path: n,
            extraData: {
                foo: "bar"
            },
            envVersion: "develop",
            success: function(t) {}
        }) : wx.navigateTo({
            url: "../../card/info/info?card_id=" + a
        });
    },
    open_map: function(t) {
        var a = t.currentTarget.dataset.lat, e = t.currentTarget.dataset.lon;
        "0" != a ? wx.openLocation({
            latitude: parseFloat(a),
            longitude: parseFloat(e),
            scale: 28
        }) : wx.showToast({
            image: "../../resource/images/static/error.png",
            title: "座标错误,无法定位!"
        });
    },
    cityedit: function(t) {
        wx.navigateTo({
            url: "../../city/cityedit/cityedit?cityid=" + t.currentTarget.id
        });
    },
    to_msg_info: function(t) {
        wx.navigateTo({
            url: "../../city/citys/citys?cityid=" + t.currentTarget.id
        });
    },
    tap_lianxita: function(t) {
        var a = t.currentTarget.dataset.uphone;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    previewImage: function(t) {
        wx.previewImage({
            current: t.currentTarget.dataset.img,
            urls: t.currentTarget.dataset.imgs
        });
    },
    onShareAppMessage: function() {},
    onNavigateTaptb: function(t) {
        var a = t.currentTarget.dataset.url, e = t.currentTarget.dataset.wx_appid, n = t.currentTarget.dataset.wx_path;
        e ? wx.navigateToMiniProgram({
            appId: e,
            path: n,
            extraData: {
                foo: "bar"
            },
            envVersion: "develop",
            success: function(t) {}
        }) : wx.navigateTo({
            url: "../info/info?card_id=" + a
        });
    }
});